#include<iostream>
#include<vector>
#include<string>
using namespace std;


class Solution {
public:
    vector<string> summaryRanges(vector<int>& nums) {
        int len = nums.size();
        int posi = 0;
        vector<string> ans;
        while (posi < len) {
            int prePos = posi;
            ans.push_back(to_string(nums[prePos]));
            while (posi < len - 1 && nums[posi] + 1 == nums[posi + 1]) {
                posi++;
            }
            if (prePos < posi) {
                ans.back() += "->";
                ans.back() += to_string(nums[posi]);
            }
            posi++;
        }
        return ans;
    }
};